/********divide the candy to the children******************************/

#include<iostream>
#include<stdlib.h>
#include<ctime>

using namespace std;



int main()
{
    int kid[100];
    int ans=0;
    int n;
    cout<<"enter the number of the kid"<<endl;
    cin>>n;
    
    int seed=time(0);
    srand((unsigned int)seed);

    for(int i=0;i<n;i++)
    {
     kid[i]=(rand()%10)*2;
    }
    
    while(1)
    {
        bool flag=true;
        for(int i=1;i<n;i++)
        {
            if(kid[0]!=kid[i])
                flag=false;
        }

        if(flag) break;

    
        for(int i=0;i<n;i++)
        {
            kid[i]=kid[i]/2;
        }

        int temp=kid[n-1];         //can use loop list improve the program
        for(int i=n-1;i>0;i--)
        {
            kid[i]+=kid[i-1];
        }
        kid[0]+=temp;

        for(int i=0;i<n;i++)
        {
            if(kid[i]%2!=0)
            {
                kid[i]++;
                ans++;
            }
        }
    }

    cout<<"the candies of every kid is "<<kid[0]<<"   "<<ans<<endl;
    
    system("pause");
    return 0;
}

